#include "../tdp2/tdp2_respreload.hpp"
#include "../tdp2/tdp2_fpsystem.hpp"
#include "../tdp2/tdp2_vfs.hpp"

using namespace TDP;

void ExtractFile(const char *filename, TDP::ResourceManagement::ResourcePreloader &preload)
{
	LargeUInt l = strlen(filename);
	Char wideName[MAX_FILE_PATH];
	for(LargeUInt i=0;i<l;i++)
		wideName[i] = static_cast<Char>(filename[i]);
	wideName[l] = static_cast<Char>(0);

	if(preload.BeginStreamingFile(wideName, true))
	{
		FILE *f = fopen(filename, "wb");
		char buf[10000];
		LargeUInt readBytes;
		LargeUInt totalBytes = 0;

		while(preload.Read(buf, 1, sizeof(buf), &readBytes))
		{
			fwrite(buf, readBytes, 1, f);
			totalBytes += readBytes;
			RDX::Threading::SleepThread(10);
		}

		preload.StopStreamingFile();
	}
}

int main(int argc, const char **argv)
{
	TDP::OS::OSFileSystem osfs(NULL, RDX_STATIC_STRING("../data"));
	TDP::ResourceManagement::MFPResourceManager mfp(&osfs);

	TDP::ResourceManagement::ResourcePreloader preload(NULL, TDP::Memory::DefaultAllocator(), 1000, sizeof(void*), &mfp);

	ExtractFile("generated/textures/stone/testss_ss1.dds", preload);
	ExtractFile("generated/textures/stone/testss_ss2.dds", preload);
	ExtractFile("generated/textures/stone/testss_ss3.dds", preload);


	return 0;
}
